package com.it.whitejotterapi.controller;

import com.it.whitejotterapi.entity.AdminUser;
import com.it.whitejotterapi.service.AdminUserService;
import com.it.whitejotterapi.tools.JsonResult;
import com.it.whitejotterapi.tools.Md5Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.security.NoSuchAlgorithmException;

/**
 * @Author: 羡羡
 * @Date: 2022/05/23/09:01
 */
@RestController
public class AdminUserController {

    @Autowired
    AdminUserService adser;
    /**
     * 用户登入
     * @param username 用户名
     * @param password 用户密码
     * @return
     */
    @RequestMapping(path = "/login",method= RequestMethod.POST)
    public JsonResult login(String username,String password) throws NoSuchAlgorithmException {
        return adser.login(username, password);
    }

    /**
     * 用户注册
     * @param username 用户名
     * @param password 用户密码
     * @param name 用户昵称
     * @param phone 电话
     * @param email 电子邮件
     * @return
     * @throws NoSuchAlgorithmException
     */
    @RequestMapping(path = "/registerus",method = RequestMethod.POST)
    public JsonResult register(String username,String password,String name,String phone,String email) throws NoSuchAlgorithmException {
        AdminUser adus=new AdminUser(username, Md5Tools.getmdresult(password),name,phone,email,1,0,0);
        return adser.registeruser(adus);
    }
}
